<?php
/**
 * @package Joomla.JoomShopping.Products
 * @author Vadim Meling
 * @website http://dell3r.ru/
 * @email dell3r@yandex.ru
 * @copyright Copyright by Dell3r Ltd. All rights reserved.
 * @license The MIT License (MIT);
 */
Defined('_JEXEC') Or Die('Restricted access');

class plgJshoppingProductsPlus_Minus_Count_Product extends JPlugin{

	Function onBeforeDisplayProductListView(&$view){
		ForEach($view->rows As $key => $product){
			$view->rows[$key]->_tmp_var_buttons = '<Br>
			<input class = "product_minus" type = "button" onclick = "
			var qty_el = document.getElementById(\'quantity'.$product->product_id.'\');
			var qty = qty_el.value;
			if( !isNaN( qty ) && qty > 1) qty_el.value--;
			var url_el = document.getElementById(\'productlink'.$product->product_id.'\');
			url_el.href=\''.$view->rows[$key]->buy_link.'&quantity=\'+qty_el.value;return false;" />

			<Input Type = "text" Name = "quantity'.$product->product_id.'" Id = "quantity'.$product->product_id.'"
			Style = "Min-Width:20px; Max-Width:100px;" Class = "inputbox" Value = "1" onChange="
			var qty_el = document.getElementById(\'quantity'.$product->product_id.'\');
			var url_el = document.getElementById(\'productlink'.$product->product_id.'\');
			url_el.href=\''.$view->rows[$key]->buy_link.'&quantity=\'+qty_el.value;
			return false;" />

			<input class = "product_plus" type = "button" onclick = "
			var qty_el = document.getElementById(\'quantity'.$product->product_id.'\');
			var qty = qty_el.value;
			if( !isNaN( qty )) qty_el.value++;
			var url_el = document.getElementById(\'productlink'.$product->product_id.'\');
			url_el.href=\''.$view->rows[$key]->buy_link.'&quantity=\'+qty_el.value;return false;" />';

			$view->rows[$key]->buy_link .= "\" Id = \"productlink".$product->product_id;
		}
	}
	Function onBeforeDisplayProductView(&$view){
		$view->_tmp_qty_unit =
			"<input class = \"product_minus\" type = \"button\" onclick = \"
			var qty_el = document.getElementById('quantity');
			var qty = parseInt(qty_el.value);
			if( !isNaN( qty ) && qty > 1) qty_el.value--;
			return false;\">

			<input class = \"product_plus\" type = \"button\" onclick = \"
			var qty_el = document.getElementById('quantity');
			var qty = parseInt(qty_el.value);
			if( !isNaN( qty )) qty_el.value++;
			return false;\">";
	}
}
?>